﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using _2QWebProxy.App_Code;

namespace _2QWebProxy.GUI
{
    public partial class ucIPAddressDenyFileTypes : UserControl
    {
        #region Utils Methods

        private void LoadIPAddress()
        {
            List<PrivacyIpAddress> list = Utils.GetPrivacyIPAddress("allow");
            cbbIPAddress.Items.Add("Add new IP Address");
            if (list.Count > 0)
            {
                foreach (PrivacyIpAddress file in list)
                {
                    cbbIPAddress.Items.Add(file);
                }
                cbbIPAddress.DisplayMember = "Name";
            }
            cbbIPAddress.SelectedIndex = 0;
        }

        private void LoadFielTypes()
        {
            List<string> list = Utils.GetCommonFileType();
            cbbFileType.DataSource = list;
        }

        private void CheckControlDomain()
        {
            txtNewIPAddress.Visible = cbbIPAddress.SelectedIndex == 0;
        }

        private void LoadListData()
        {
            dgvData.Rows.Clear();
            List<DenyFileType> list = Utils.GetListIPAddressDenyFileType();
            bool flag = false;
            int num = 0;
            for (int i = 0; i < list.Count; i++)
            {
                flag = true;
                foreach (string file in list[i].FileTypes)
                {
                    dgvData.Rows.Add();
                    if (flag)
                        dgvData.Rows[num].Cells["IPAddress"].Value = list[i].Name;
                    dgvData.Rows[num].Cells["FileType"].Value = file;
                    dgvData.Rows[num].Cells["IPAddressHidden"].Value = list[i].Name;
                    num++;
                    flag = false;
                }
            }
        }

        #endregion

        public ucIPAddressDenyFileTypes()
        {
            InitializeComponent();
            LoadIPAddress();
            LoadFielTypes();
            LoadListData();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {

        }

        private void btnRemove_Click(object sender, EventArgs e)
        {

        }

        private void btnRemoveAll_Click(object sender, EventArgs e)
        {

        }
    }
}
